package com.nuoniu.sibanyun.controller.crm.call;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.call.CrmCallAgent;
import com.nuoniu.sibanyun.entity.crm.call.dto.*;
import com.nuoniu.sibanyun.service.crm.call.ICrmCallAgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客户管理-坐席 前端控制器
 * </p>
 *
 * @author 白强
 * @since 2022-04-15
 */
@RestController
@RequestMapping("/crm/callAgent")
@Api(value="坐席管理 ",tags={"坐席管理"})
public class CrmCallAgentController extends BaseController {


    @Autowired
    private ICrmCallAgentService callAgentService;

    @PostMapping("pageCrmCallAgentBySystem")
    @ApiOperation(value = "分页查询 坐席（系统）")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult pageCrmCallAgentBySystem(@RequestBody CrmCallAgentSearchDto crmCallAgentSearchDto) {
        return HttpResult.ok(callAgentService.pageCrmCallAgentBySystem(crmCallAgentSearchDto));
    }

    @PostMapping("saveCrmCallAgent")
    @ApiOperation(value = "保存 坐席")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult saveCrmCallAgent(@RequestBody CrmCallAgent crmCallAgent){
        callAgentService.saveCrmCallAgent(crmCallAgent);
        return HttpResult.ok();
    }

    @PostMapping("deleteByIds")
    @ApiOperation(value = "批量删除")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult deleteByIds(@RequestBody IdsAndCompanyIdDto dto){
        callAgentService.deleteByIds(dto);
        return HttpResult.ok();
    }


    @PostMapping("batchEnable")
    @ApiOperation(value = "批量启用")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult batchEnable(@RequestBody IdsAndCompanyIdDto dto){
        callAgentService.batchEnable(dto);
        return HttpResult.ok();
    }

    @PostMapping("batchDisable")
    @ApiOperation(value = "批量暂停")
    @PreAuthorize("'system' == authentication.principal ")
    public HttpResult batchDisable(@RequestBody IdsAndCompanyIdDto dto){
        callAgentService.batchDisable(dto);
        return HttpResult.ok();
    }

    @PostMapping("pageCrmCallAgentCustomerVo")
    @ApiOperation(value = "分页查询 坐席（租户）")
    public HttpResult pageCrmCallAgentCustomerVo(@RequestBody CrmCallAgentSearchDto crmCallAgentSearchDto){
        return HttpResult.ok(callAgentService.pageCrmCallAgentCustomerVo(crmCallAgentSearchDto));
    }

//    @PostMapping("distributeAgent")
//    @ApiOperation(value = "分配 坐席（租户）")
//    public HttpResult distributeAgent(Long agentId,Long userId,String userName){
//        callAgentService.distributeAgent(agentId, userId, userName);
//        return HttpResult.ok();
//    }
//
//    @PostMapping("pageCrmCallAgentUserVo")
//    @ApiOperation(value = "坐席用户分配情况")
//    public HttpResult pageCrmCallAgentUserVo(@RequestBody CrmCallAgentUserDto dto){
//        return HttpResult.ok(callAgentService.pageCrmCallAgentUserVo(dto));
//    }
//
//    @PostMapping("saveAgentOrder")
//    @ApiOperation(value = "新购坐席")
//    public HttpResult saveAgentOrder(@RequestBody AgentOrderDto agentOrderDto){
//        callAgentService.saveAgentOrder(agentOrderDto);
//        return HttpResult.ok();
//    }
//
//    @PostMapping("dealAgentOrder")
//    @ApiOperation(value = "坐席订单交易成功")
//    public HttpResult dealAgentOrder(@RequestBody DealAgentOrderDto dealAgentOrderDto){
//        callAgentService.dealAgentOrder(dealAgentOrderDto);
//        return HttpResult.ok();
//    }

    @PostMapping("saveAgentByCompany")
    @ApiOperation(value = "租户 新增坐席")
    public HttpResult saveAgentByCompany(@RequestBody CrmCallAgent crmCallAgent){
        callAgentService.saveAgentByCompany(crmCallAgent);
        return HttpResult.ok();
    }

    @PostMapping("deleteByIdsByCompany")
    @ApiOperation(value = "批量删除 坐席(租户)")
    public HttpResult deleteByIdsByCompany(@RequestBody List<Long> ids){
        callAgentService.deleteByIdsByCompany(ids);
        return HttpResult.ok();
    }

    @PostMapping("batchEnableByCompany")
    @ApiOperation(value = "批量启用坐席(租户)")
    public HttpResult batchEnableByCompany(@RequestBody List<Long> ids){
        callAgentService.batchEnableByCompany(ids);
        return HttpResult.ok();
    }

    @PostMapping("batchDisableByCompany")
    @ApiOperation(value = "批量禁用坐席(租户)")
    public HttpResult batchDisableByCompany(@RequestBody List<Long> ids){
        callAgentService.batchDisableByCompany(ids);
        return HttpResult.ok();
    }


    @GetMapping("getMyCrmCallAgent")
    @ApiOperation(value = "获取用户的坐席")
    public HttpResult getMyCrmCallAgent(){
        return HttpResult.ok(callAgentService.getMyCrmCallAgent());
    }

}
